const api = {
  doc: {
    doc: {
      ocrImageText: '/ocrImageText'
    }
  },
  mdm: {
    riskSz: {
      attachment: {
        download: '/download'
      }
    }
  },
  rg: {
    riskSz: {
      reportTemplate: {
        list: '/list',
        get: '/get'
      },
      reportTemplateConfig: {
        getConfigByTemplateId: '/getConfigByTemplateId'
      },
      reportTemplateSubitem: {
        getTemplateSubitemTree: '/getTemplateSubitemTree'
      },
      reportRecord: {
        list: '/list',
        get: '/get',
        create: '/create',
        download: '/download'
      },
      reportGen: {
        getVarValueByTemplate: '/getVarValueByTemplate'
      }
    }
  },
  service: {
    riskSz: {
      announcementClassify: {
        getAllTreeList: '/getAllTreeList'
      },
      file: {
        uploadOneFile: '/uploadOneFile',
        addFileInfo: '/addFileInfo',
        queryFileProcess: '/queryFileProcess',
        deleteFileInfo: '/deleteFileInfo',
        pdf: '/pdf'
      },
      fileWork: {
        batchConvertAndExtract: '/batchConvertAndExtract', // 批量提取
        convertAndExtract: '/convertAndExtract', // 单个文件提取
        extract: '/extract' // 重新提取
      },
      data: {
        getTableColumns: '/getTableColumns',
        getBusinessDetail: '/getBusinessDetail'
      }
    }
  }
}
function toUnderline(str: string) {
  return str.replace(/([A-Z])/g, '-$1').toLowerCase()
}

function setApiPrefix(apiObj: any, prefix = '', level = 0) {
  for (const key in apiObj) {
    if (typeof apiObj[key] === 'object' && apiObj[key] !== null) {
      setApiPrefix(
        apiObj[key],
        (level == 0 ? '/api-c1' : '') + toUnderline(prefix) + '/' + (apiObj.key || key),
        level + 1
      )
    } else {
      apiObj[key] = prefix + apiObj[key]
    }
  }
}
setApiPrefix(api)

export default api
